package hu.jonas.allunit.views;

import hu.jonas.allunit.model.TestResult;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

public class TestResultSorter extends ViewerSorter {

	private int sortColumn = 2;
	private int sortDirection = -1;
	
	@Override
	public int compare(Viewer viewer, Object e1, Object e2) {
		TestResult t1 = (TestResult) e1;
		TestResult t2 = (TestResult) e2;

		switch (sortColumn) {
		case 0:
			return t1.getTestClassName().compareTo(t2.getTestClassName()) * sortDirection;
		case 1:
			return t1.getTestMethodName().compareTo(t2.getTestMethodName()) * sortDirection;
		case 2:
			return Double.compare(t1.getElapsedTime(), t2.getElapsedTime()) * sortDirection;
		}
		return 0;
	}

	public int getSortColumn() {
		return sortColumn;
	}

	public void setSortColumn(int sortColumn) {
		this.sortColumn = sortColumn;
	}

	public int getSortDirection() {
		return sortDirection;
	}

	public void setSortDirection(int sortDirection) {
		this.sortDirection = sortDirection;
	}
	
}
